import { BasicColumn, FormSchema } from '/@/components/Table';
import { ref } from 'vue';
import dayjs from 'dayjs';
const dates = ref();
export const columns: BasicColumn[] = [
  {
    title: '刷卡时间',
    dataIndex: 'rtime',
    width: 180,
    align: 'center',
  },
  {
    title: '学生姓名',
    dataIndex: ['item', 'name'],
    width: 120,
    align: 'center',
  },
  {
    title: '性别',
    dataIndex: ['item', 'sex'],
    width: 120,
    align: 'center',
  },
  {
    title: '学生卡号',
    dataIndex: 'stid',
    align: 'center',
    width: 120,
  },
  {
    title: '一卡通账户',
    dataIndex: ['item', 'account'],
    align: 'center',
    width: 120,
  },
  {
    title: '卡状态',
    dataIndex: ['text1', 'log'],
    align: 'center',
    width: 120,
  },
  {
    title: '操作存储结果',
    dataIndex: ['text2', 'log'],
    align: 'center',
    width: 120,
  },
  {
    title: '操作结果',
    dataIndex: ['text3', 'log'],
    align: 'center',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'stid',
    label: '学生卡号',
    component: 'Input',
    colProps: { span: 6 },
  },
  // {
  //   field: 'cid',
  //   label: '卡硬件号ID',
  //   component: 'Input',
  //   colProps: { span: 6 },
  // },
  {
    field: 'rtime',
    label: '刷卡时间',
    component: 'RangePicker',
    colProps: { span: 12 },
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['请选择开始日期时间', '请选择结束日期时间'],
      allowClear: false,
      disabledDate: (current) => {
        if (!dates.value || (dates.value as any).length === 0) {
          return false;
        }
        const tooLate = dates.value[0] && current.diff(dates.value[0], 'month') > 6;
        const tooEarly = dates.value[1] && dayjs(dates.value[1]).diff(current, 'month') > 6;
        return tooEarly || tooLate;
      },
      onCalendarChange: (val) => {
        dates.value = val;
      },
    },
    defaultValue: [
      dayjs().subtract(30, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss'),
    ],
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '主键',
    field: 'idx',
    component: 'Input',
    show: false,
  },
  {
    label: '学生姓名',
    field: 'name',
    component: 'Input',
  },
  {
    label: '学生卡号',
    field: 'stid',
    component: 'Input',
  },
  {
    label: '一卡通账户',
    field: 'account',
    component: 'Input',
  },
  {
    label: '身份证号',
    field: 'idcard',
    component: 'Input',
  },
  {
    label: '生效时间',
    field: 'stime',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD HH:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      //是否显示今天按钮
      showToday: true,
      showTime: true,
    },
  },
  {
    label: '失效时间',
    field: 'etime',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD HH:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      //是否显示今天按钮
      showToday: true,
      showTime: true,
    },
  },
  {
    label: '当前状态',
    field: 'state',
    component: 'RadioButtonGroup',
    componentProps: {
      //options里面由一个一个的radio组成,支持disabled禁用
      options: [
        { label: '有效', value: 1 },
        { label: '黑名单', value: -2 },
      ],
    },
  },
];
